var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmuleixing:$("#xiangmuleixing").val(),
        lunci:$("#lunci").val(),

        usernum:'',
        guigexuhao:'',
        drugname:'',
        jicaiyao:'',
        jiyao:'',

        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,


        qiyepass:'',
        jicaipass:'',
        jicaishengyu:'',

        issubmited:false,
        isallsubmited:false,


        pageIndex : 1,
        pageSize :9999,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");

        _this.findIsacticed();
    },
    methods : {

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.usernum = data.zhuangjiashu;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getResultCount();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        remove:function (){
           this.guigexuhao="";
           this.drugname="";
           this.jicaiyao="";
           this.jiyao="";
           this.findBiaojuelist();
        },

        toRefresh:function (){
            location.reload();
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/shengchanqiye/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                lunci :_this.lunci,
                guigexuhao:_this.guigexuhao,
                drugname:_this.drugname,
                jiyao:_this.jiyao,
                jicaiyao:_this.jicaiyao,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;

                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">品种序号</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">药品分类</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >药品品名</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >剂型</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">规格序号</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:80px;\" rowspan=\"2\" >药品名称</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:80px;\" rowspan=\"2\" >规格</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >单位</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >医保类别</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\"  >上级检查通报</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\"  >未挂网</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >无配送企业</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >原国谈</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >通过一致性评价</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >国家保密配方</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >中药保护品种</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >价格（元）</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >原研</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >基药</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >集采</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >院本部</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">秦淮</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:110px;\" rowspan=\"2\">产品编码</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:150px;\" rowspan=\"2\" >生产企业</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:150px;\" rowspan=\"2\" >备注</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\">上轮票数</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\">表决意见（同意请打勾）</td>\n" +
                            "    </tr>\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:150px;\" colspan='3' >淘汰原则</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:320px;\" colspan='4'>绝对优先</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" colspan='2'>相对优先</td>\n" +
                            "    </tr></thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";

                        if(data.ShengchanList.length > 0){
                            _this.show = true;
                            _this.Shengchanqiyelist=data.ShengchanList;

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.ShengchanList.length; i++) {
                                var mmShengchan = data.ShengchanList[i];

                                var mmPinzhongbinahao=mmShengchan.pinzhongbianhao;
                                var mmyaopinfenlei=mmShengchan.beizhu1;
                                var mmYaopinpingming=mmShengchan.yaopinpinming;

                                var mmPinguiList = mmShengchan.pinguilist;
                                var mmPinzhongHebingshu = mmShengchan.pinzhonghebinghang;

                                for (var j = 0; j < mmPinguiList.length; j++) {
                                    var s=0;

                                    var mmPinguilist = mmPinguiList[j];

                                    var mmPinguixuhao = parseInt(mmPinguilist.pinguixuhao);
                                    var mmYaopinmingcheng = mmPinguilist.yaopinmingcheng;
                                    var mmGuige = mmPinguilist.guige;
                                    var mmDanwei = mmPinguilist.danwei;
                                    var mmYibaoleibie = mmPinguilist.yibaoleibie;
                                    var mmPinguileibie=mmPinguilist.pinguileibie;
                                    var mmJixing=mmPinguilist.jixing;

                                    var mmShengchanqiyeList= mmPinguilist.shengchanqiyelist;
                                    var mmPinguiHebingshu = mmPinguilist.pinguihebinghang;

                                    for (var k = 0; k < mmShengchanqiyeList.length; k++) {
                                        var mmlist = mmShengchanqiyeList[k];
                                        var mmId=mmlist.id;
                                        var mmJianchatongbao = mmlist.jianchatongbao;
                                        var mmWeiguawang = mmlist.weiguawang;
                                        var mmWupeisongqiyehu = mmlist.wupeisongqiye;
                                        var mmYuanguotan = mmlist.yuanguotan;
                                        var mmYizhixingpingjia= mmlist.yizhixingpingjia;
                                        var mmBaomipeifang=mmlist.baomipeifang;
                                        var mmBaohupinzhong=mmlist.baohupinzhong;
                                        var mmJiage = mmlist.jiage;
                                        var mmYuanyan = mmlist.yuanyan;
                                        var mmJiyao = mmlist.jiyao;
                                        var mmJicai = mmlist.jicai;
                                        var mmYuanbenbu = mmlist.yuanbenbu;
                                        var mmQinhuai = mmlist.qinhuai;
                                        var mmChanpinbianma= mmlist.chanpinbianma;
                                        var mmShengchanqiye = mmlist.shengchanqiye;
                                        var mmBeizhu = mmlist.beizhu;
                                        var mmResult = mmlist.result;
                                        var mmLastScore = mmlist.beizhu12+"/"+_this.usernum;

                                        var mmHuanhangfu = "";
                                        var mmerjihe="";
                                        var mmyijihe="";
                                        var mmsanjihe="";
                                        if (k != 0) {
                                            if(mmJicai =='是'){
                                                mmHuanhangfu = "<tr style='background: lightblue'>";
                                            }else{
                                                mmHuanhangfu = "<tr>";
                                            }
                                        }else{
                                            mmerjihe = "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinguiHebingshu + "'>" + mmJixing + "</td>";
                                            mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinguiHebingshu + "'>" + mmPinguixuhao + "</td>";
                                            mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 80px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmYaopinmingcheng + "</td>";
                                            mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 80px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'  rowspan='" + mmPinguiHebingshu + "'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                            mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmDanwei + "</td>";
                                            mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmYibaoleibie + "</td>";
                                            mmsanjihe = "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmPinguileibie + "</td>";
                                        }
                                        if(j==0 &&s==0){
                                            mmyijihe= "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongbinahao + "</td>";
                                            mmyijihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmyaopinfenlei + "</td>";
                                            mmyijihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmYaopinpingming + "</td>";

                                            s= 1;
                                        }

                                        mmHtml +=mmyijihe;
                                        mmHtml +=mmerjihe;

                                        var mmBtndiv="";
                                        if(_this.issubmited){
                                            if(mmResult==null||mmResult==0){
                                                mmBtndiv="<div id='div_"+mmId+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled onclick=\"toVote('"+mmId+"','"+mmPinzhongbinahao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmId+"' class='cbcss' type=\"checkbox\"></div>";
                                            }
                                            if(mmResult==1){
                                                mmBtndiv="<div id='div_"+mmId+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled checked onclick=\"toVote('"+mmId+"','"+mmPinzhongbinahao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmId+"' class='cbcss' type=\"checkbox\"></div>";
                                            }
                                        }
                                        if(!_this.issubmited) {
                                            if(mmResult==null||mmResult==0){
                                                mmBtndiv="<div id='div_"+mmId+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" onclick=\"toVote('"+mmId+"','"+mmPinzhongbinahao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmId+"' class='cbcss' type=\"checkbox\"></div>";
                                            }
                                            if(mmResult==1){
                                                mmBtndiv="<div id='div_"+mmId+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" checked onclick=\"toVote('"+mmId+"','"+mmPinzhongbinahao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmId+"'  class='cbcss' type=\"checkbox\"></div>";
                                            }
                                        }

                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jianchatongbao' style=\"text-align:center;\">" + mmJianchatongbao + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_weiguawang' style=\"text-align:center;\">" + mmWeiguawang + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_wupeisongqiye' style=\"text-align:center;\">" + mmWupeisongqiyehu + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yuanguotan' style=\"text-align:center;\">" + mmYuanguotan + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yizhixingpingjia' style=\"text-align:center;\">" + mmYizhixingpingjia + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden;'><a id='a_"+mmId+"_baomipeifang' title='" + mmBaomipeifang + "'><div id='div_"+mmId+"_baomipeifang' style=\"text-align:center;text-overflow: ellipsis; overflow: hidden;\">" + mmBaomipeifang + "</div></a></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'><div id='div_"+mmId+"_baohupinzhong' style=\"text-align:center;\">" + mmBaohupinzhong + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jiage' style=\"text-align:center;\">" + mmJiage + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yuanyan' style=\"text-align:center;\">" + mmYuanyan + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jiyao' style=\"text-align:center;\">" + mmJiyao + "</div></td>";
                                        if(mmJicai=="是"){
                                            mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;background:lightgreen '><div id='div_"+mmId+"_jicai' style=\"text-align:center;\">" + mmJicai + "</div></td>";
                                        }else{
                                            mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jicai' style=\"text-align:center;\">" + mmJicai + "</div></td>";
                                        }

                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmYuanbenbu + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmQinhuai + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 110px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a id='a_"+mmId+"_chanpinbianma' title='" + mmChanpinbianma + "'><div id='div_"+mmId+"_chanpinbianma' style=\"text-align:center;text-overflow: ellipsis; overflow: hidden;\">" + mmChanpinbianma + "</div></a></td>";
                                        // mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmChanpinbianma + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 150px;'><div id='div_"+mmId+"_shengchanqiye' style=\"text-align:center;\">" + mmShengchanqiye + "</div></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width: 150px;'><div id='div_"+mmId+"_beizhu' style=\"text-align:center;\">" + mmBeizhu + "</div></td>";
                                        if (_this.lunci>1){
                                            mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'><div id='div_"+mmId+"_lastscore' style=\"text-align:center;\">" + mmLastScore + "</div></td>";
                                        }else{
                                            mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'><div id='div_"+mmId+"_lastscore' style=\"text-align:center;\">无</div></td>";
                                        }
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBtndiv + "</td>";
                                        mmHtml += "</tr>";
                                    }
                                }
                            }
                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</tbody></table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/shengchanqiyetoupiao/getResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.qiyepass=data.qiyepass;
                        _this.jicaipass=data.jicaipass;
                        _this.jicaishengyu=data.jicaishengyu;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        votejicai:function(){
            var _this = this;

            layer.open({type: 3});
            $.post('/shengchanqiyetoupiao/vote_jicai', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        layer.alert("表决成功");
                        location.reload()
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },

        tosubmit:function (){
            var _this = this;
            layer.confirm("是否确认提交？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.post('/shengchanqiyetoupiao/submit', {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    rdm : Math.random()
                },function(ppData) {
                    layer.closeAll("loading");
                    if(ppData != null){
                        if(ppData.result == "1"){
                            _this.issubmited=true;
                            layer.alert("提交成功");
                            _this.findBiaojuelist();

                            setTimeout(function(){
                                _this.checkIsAllSubmited();
                            },5000);

                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                },"json");
            })
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{

        //监控分页情况，刷新列表
        pageIndex : function(){
            this.findBiaojuelist();
        }

    }
})